﻿using System.Text;
using NewLife.Data;
using NewLife.Messaging;
using NewLife.Remoting;

namespace newlife.rpc.client.api
{
    /// <summary>
    /// 自定义 ApiClient
    /// </summary>
    public class MyApiClient(string urls) : ApiClient(urls)
    {
        protected override void OnReceive(IMessage message, ApiReceivedEventArgs e)
        {
            // 客户端发送请求后，服务端响应或者主动通知都会触发此函数
            var msg = Encoder.Decode(message);
            if (msg != null && msg.Data?.Length > 0)
            {
                string data = Encoding.UTF8.GetString(msg.Data.ReadBytes());
                Console.WriteLine($"服务端通知：{msg.Action} => {data}");
            }
        }
    }
}
